home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / Online / Term / Extras / Source / gtlayout-source.lha / LTP_BitMap.c < prev    next >
C/C++ Source or Header  |  1996-10-11  |  2KB  |  136 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1996 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. LONG
  15. LTP_GetDepth(struct BitMap *BitMap)
  16. {
  17.     if(V39)
  18.         return((LONG)GetBitMapAttr(BitMap,BMA_DEPTH));
  19.     else
  20.         return(BitMap->Depth);
  21. }
  22.  
  23. VOID
  24. LTP_DeleteBitMap(struct BitMap *BitMap,BOOL Chip)
  25. {
  26.     if(V39 && !Chip)
  27.         FreeBitMap(BitMap);
  28.     else
  29.     {
  30.         if(BitMap)
  31.         {
  32.             LONG i,*Sizes,Width,Height;
  33.  
  34.             Sizes = &((LONG *)BitMap)[-2];
  35.  
  36.             Width = Sizes[0];
  37.             Height = Sizes[1];
  38.  
  39.             if(Width && Height)
  40.             {
  41.                 for(i = 0 ; i < BitMap->Depth ; i++)
  42.                     FreeRaster(BitMap->Planes[i],Width,Height);
  43.             }
  44.             else
  45.             {
  46.                 for(i = 0 ; i < BitMap->Depth ; i++)
  47.                     FreeVec(BitMap->Planes[i]);
  48.             }
  49.  
  50.             FreeVec(Sizes);
  51.         }
  52.     }
  53. }
  54.  
  55. struct BitMap *
  56. LTP_CreateBitMap(LONG Width,LONG Height,LONG Depth,struct BitMap *Friend,BOOL Chip)
  57. {
  58.     struct BitMap *BitMap;
  59.  
  60.     if(V39 && !Chip)
  61.         BitMap = AllocBitMap(Width,Height,Depth,BMF_MINPLANES,Friend);
  62.     else
  63.     {
  64.         LONG *Sizes;
  65.  
  66.         if(!(Sizes = (LONG *)AllocVec(sizeof(LONG) * 2 + sizeof(struct BitMap),MEMF_ANY | MEMF_PUBLIC)))
  67.             BitMap = NULL;
  68.         else
  69.         {
  70.             LONG i;
  71.  
  72.             BitMap = (struct BitMap *)&Sizes[2];
  73.  
  74.             InitBitMap(BitMap,Depth,Width,Height);
  75.  
  76.             for(i = 0 ; i < Depth ; i++)
  77.             {
  78.                 if(!(BitMap->Planes[i] = AllocRaster(Width,Height)))
  79.                 {
  80.                     LONG j;
  81.  
  82.                     for(j = 0 ; j < i ; j++)
  83.                         FreeRaster(BitMap->Planes[j],Width,Height);
  84.  
  85.                     FreeVec(Sizes);
  86.  
  87.                     return(NULL);
  88.                 }
  89.             }
  90.  
  91.             Sizes[0] = Width;
  92.             Sizes[1] = Height;
  93.  
  94.             if(Chip)
  95.             {
  96.                 ULONG Type = MEMF_CHIP;
  97.  
  98.                 for(i = 0 ; i < Depth ; i++)
  99.                     Type &= TypeOfMem(BitMap->Planes[i]);
  100.  
  101.                 if(!(Type & MEMF_CHIP))
  102.                 {
  103.                     LONG PageSize;
  104.  
  105.                     for(i = 0 ; i < Depth ; i++)
  106.                     {
  107.                         FreeRaster(BitMap->Planes[i],Width,Height);
  108.                         BitMap->Planes[i] = NULL;
  109.                     }
  110.  
  111.                     PageSize = BitMap->BytesPerRow * BitMap->Rows;
  112.  
  113.                     for(i = 0 ; i < Depth ; i++)
  114.                     {
  115.                         if(!(BitMap->Planes[i] = AllocVec(PageSize,MEMF_CHIP)))
  116.                         {
  117.                             LONG j;
  118.  
  119.                             for(j = 0 ; j < i ; j++)
  120.                                 FreeVec(BitMap->Planes[j]);
  121.  
  122.                             FreeVec(Sizes);
  123.  
  124.                             return(NULL);
  125.                         }
  126.                     }
  127.  
  128.                     Sizes[0] = Sizes[1] = 0;
  129.                 }
  130.             }
  131.         }
  132.     }
  133.  
  134.     return(BitMap);
  135. }
  136.